import java.util.Arrays;
import java.util.Comparator;

abstract class Car{
    private String color;
    private int age;

    public Car(){
        this.color = "红";
        this.age = 6;
    }

    public Car(String color,int age){
        this.color = color;
        this.age = age;
    }

    public String getColor() {
        return color;
    }

    @Override
    public String toString() {
        return "Car{" +
                "color='" + color + '\'' +
                ", age=" + age +
                '}';
    }

    public abstract void hotWheel();

}

class SafeCar extends Car{
    public SafeCar(String color,int age){
        super(color,age);
    }

    @Override
    public void hotWheel() {
        System.out.println("安全车正在领航!");
    }

}

class F1 extends Car implements Action,Compare{
    private int rate;

    public F1(String color,int age,int rate){
        super(color,age);
        this.rate = rate;
    }

    public int getRate() {
        return rate;
    }

    public void harryUp(){
       System.out.println(this.getColor() + "车正在加速！");
    }

    @Override
    public void hotWheel() {
        System.out.println(this.getColor() + "车正在热胎!");
    }

    @Override
    public void cornering() {
        System.out.println(this.getColor() + "车正在过弯!");
    }

    @Override
    public void slowDown() {
        System.out.println(this.getColor() + "车正在减速！");
    }

    @Override
    public int compareSpeed(F1 car) {
       return car.rate - this.rate;
    }

    @Override
    public String toString() {
        return "F1{" +
                "rate=" + rate +
                '}';
    }

}

class RateComparator implements Comparator<F1> {
    @Override
    public int compare(F1 car1,F1 car2){
        return car1.getRate() - car2.getRate();
    }
}

public class Test {
    public static void main(String[] args) {
        F1 f1 = new F1("绿",2,4500);
        SafeCar f2 = new SafeCar("橙",2);
        f2.hotWheel();
        f1.hotWheel();
        f1.harryUp();
        f1.slowDown();
        f1.cornering();

        int speed1 = f1.compareSpeed(new F1("黑",4,1300));
        System.out.println("两车速度差为：" + speed1);

        //速率比较器
        RateComparator ratecomparator = new RateComparator();
        int speed2 = ratecomparator.compare(f1,new F1("紫",4,4400));
        System.out.println("两车速度差为：" + speed2);

        F1[] cars = new F1[4];
        cars[0] = new F1("白",1,3088);
        cars[1] = new F1("褐",3,2388);
        cars[2] = new F1("橙",5,3588);
        cars[3] = new F1("蓝",2,2788);

        Arrays.sort(cars,ratecomparator);
        System.out.println(Arrays.toString(cars));
    }
}
